package com.cn.ycy.service;

import com.cn.ycy.mapper.UserMapper;
import com.cn.ycy.dto.User;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

  @Autowired(required = false)
  UserMapper userMapper;

  @Value("${app.id}")
  String appid;

  public PageInfo<User> selectPage(int pageNum, int pageSize,String username) {
    Page<Object> objects = PageHelper.startPage(pageNum, pageSize);
    List<User> users = userMapper.selectAll(username);
    PageInfo<User> pageInfo = new PageInfo<>(users);
    return pageInfo;
  }

  public Boolean update(User user) {
    int i = userMapper.update(user);
    return i > 0 ? true: false;
  }

  public Boolean insert(User user){
    int i = userMapper.insert(user);
    return i > 0 ? true: false;
  }

  public Boolean delete(User user){
    int delete = userMapper.delete(user.getUserId());
    return true;
  }

}
